/*这里是登录注册页面的左右移动*/
var loginBtn=document.getElementsByClassName("loginBtn")[0];
var loginBtnContainer=document.getElementsByClassName("loginBtnContainer")[0];
var handoverLogin=document.getElementsByClassName("handoverLogin")[0];
var singBtnContainer=document.getElementsByClassName("singBtnContainer")[0];
var handoverSign=document.getElementsByClassName("handoverSign")[0];
var signBtn=document.getElementsByClassName("signBtn")[0];
loginBtn.onclick=function(){
    loginBtnContainer.style.left="100%";
    handoverSign.style.right="100%";
    setTimeout(function(){
        handoverLogin.style.left="0";
        singBtnContainer.style.right="0";
    },300);
}
signBtn.onclick=function(){
    handoverLogin.style.left="100%";
    singBtnContainer.style.right="100%";
    setTimeout(function(){
        loginBtnContainer.style.left="0";
        handoverSign.style.right="0";
    },300);
}
/*随机数做验证码*/
var comple=document.getElementsByClassName("comple")[0];
var random;
function num(){
    random=Math.floor(Math.random()*9000+1000);
    comple.innerHTML=random;
}
num();
comple.onclick=function(){
    num();
}
/*切换其他方式注册*/
// var cut=document.getElementsByClassName("cut")[0];
// var wayEmil=document.getElementsByClassName("wayEmil");
// var wayPhone=document.getElementsByClassName("wayPhone");
// var signWay=document.getElementsByClassName("signWay")[0];
// var signInputContainer=document.getElementsByClassName("signInputContainer")[0];
// var signEmail=document.getElementsByClassName("signEmail")[0];
// var returnSignEmail=document.getElementsByClassName("returnSignEmail")[0];
// var phoneSign=document.getElementsByClassName("phoneSign")[0];
// var returnSignPhone=document.getElementsByClassName("returnSignPhone")[0];
// cut.onclick=function(){
//     signInputContainer.style.display="none";
//     signWay.style.display="block";
//     signEmail.style.display="none";
//     phoneSign.style.display="none";
// }
// wayEmil[1].onclick=function(){
//     signInputContainer.style.display="none";
//     signWay.style.display="none";
//     signEmail.style.display="block";
//     phoneSign.style.display="none";
// }
// returnSignEmail.onclick=function(){
//     signInputContainer.style.display="none";
//     signWay.style.display="block";
//     signEmail.style.display="none";
//     phoneSign.style.display="none";
// }
// var returnL=document.getElementsByClassName("returnL")[0];
// returnL.onclick=function(){
//     signInputContainer.style.display="block";
//     signWay.style.display="none";
//     signEmail.style.display="none";
//     phoneSign.style.display="none";
// }
// wayPhone[1].onclick=function(){
//     signInputContainer.style.display="none";
//     signWay.style.display="none";
//     signEmail.style.display="none";
//     phoneSign.style.display="block";
// }
// returnSignPhone.onclick=function(){
//     signInputContainer.style.display="none";
//     signWay.style.display="block";
//     signEmail.style.display="none";
//     phoneSign.style.display="none";
// }
/*隐私协议*/
var privacyInput=document.getElementsByClassName("privacyInput")[0];
var sign_btn=document.getElementsByClassName("sign_btn")[0];
let signTrue=document.getElementsByClassName("signTrue")[0];
sign_btn.style.backgroundColor="#8d9299";
privacyInput.onclick=function(){
    if(privacyInput.checked==true){
        sign_btn.style.backgroundColor="";
        sign_btn.style.cursor="pointer";
        sign_btn.onclick=function(){
            if(signTrue.value!==comple.innerHTML){
                Tips("验证码不正确");
            }else if(signpassword[0].value!==signpassword[1].value){
                signpassword[0].style.border="1px solid red";
                signpassword[1].style.border="1px solid red";
                Tips("两次密码不一致");
            }else{
                Sign();
            }
        }
    }else{
        sign_btn.style.backgroundColor="#8d9299";
        sign_btn.style.cursor="no-drop";
        sign_btn.onclick=function(){

        }
    }
}

/*其他登录方式*/
// var cutLogin=document.getElementsByClassName("cutLogin")[0];
// var loginInputContainer=document.getElementsByClassName("loginInputContainer")[0];
// var loginWay=document.getElementsByClassName("loginWay")[0];
// var returnLogin=document.getElementsByClassName("returnLogin")[0];
// var emailLogin=document.getElementsByClassName("emailLogin")[0];
// var returnLoginEmail=document.getElementsByClassName("returnLoginEmail")[0]
// var phoneLogin=document.getElementsByClassName("phoneLogin")[0];
// var returnLoginPhone=document.getElementsByClassName("returnLoginPhone")[0];
// cutLogin.onclick=function(){
//     loginInputContainer.style.display="none";
//     loginWay.style.display="block";
//     emailLogin.style.display="none";
//     phoneLogin.style.display="none";
// }
// returnLogin.onclick=function(){
//     loginInputContainer.style.display="block";
//     loginWay.style.display="none";
//     emailLogin.style.display="none";
//     phoneLogin.style.display="none";
// }
// wayEmil[0].onclick=function(){
//     loginInputContainer.style.display="none";
//     loginWay.style.display="none";
//     emailLogin.style.display="block";
//     phoneLogin.style.display="none";
// }
// returnLoginEmail.onclick=function(){
//     loginInputContainer.style.display="none";
//     loginWay.style.display="block";
//     emailLogin.style.display="none";
//     phoneLogin.style.display="none";
// }
// wayPhone[0].onclick=function(){
//     loginInputContainer.style.display="none";
//     loginWay.style.display="none";
//     emailLogin.style.display="none";
//     phoneLogin.style.display="block";
// }
// returnLoginPhone.onclick=function(){
//     loginInputContainer.style.display="none";
//     loginWay.style.display="block";
//     emailLogin.style.display="none";
//     phoneLogin.style.display="none";
// }
let userName=document.getElementsByClassName("userName")[0];
let password=document.getElementsByClassName("password")[0];
let login_btn=document.getElementsByClassName("login_btn")[0];
let error=document.getElementsByClassName("error");
let tips=document.getElementsByClassName("tips")[0];
/*登录*/
function Login(){
    $.ajax({
        type:'post',
        url:"../user/loginAccount",
        async:true,
        data:{
            account:userName.value,
            password:password.value,
        },
        success:function(data){
            if(data.code==0){
                    sessionStorage.setItem("account",data.data.account);
                    sessionStorage.setItem("age",data.data.age);
                    sessionStorage.setItem("birthday",data.data.birthday);
                    sessionStorage.setItem("email",data.data.email);
                    sessionStorage.setItem("id",data.data.id);
                    sessionStorage.setItem("nickname",data.data.nickname);
                    sessionStorage.setItem("password",data.data.password);
                    sessionStorage.setItem("realname",data.data.realname);
                    sessionStorage.setItem("registTime",data.data.registTime);
                    sessionStorage.setItem("sex",data.data.sex);
                    sessionStorage.setItem("src",data.data.src);
                    sessionStorage.setItem("vip",data.data.vip);
                    sessionStorage.setItem("telephone",data.data.telephone);
                    userName.style.border="1px solid green";
                    password.style.border="1px solid green";
                    Tips("登录成功");
                    setTimeout(function(){
                        window.location.href="../tooIndex";
                    },1000)
            }else{
                userName.style.border="1px solid red";
                password.style.border="1px solid red";
                Tips("账号或密码错误");
            }
        }
    });
}
login_btn.onclick=function(){
    Login();
}


    userName.onfocus=function(){
        error[0].style.opacity="0";
        error[1].style.opacity="0";
        userName.style.border="0";
        password.style.border="0";
    }
    password.onfocus=function(){
        error[0].style.opacity="0";
        error[1].style.opacity="0";
        userName.style.border="0";
        password.style.border="0";
    }
/*注册*/
var signuserName=document.getElementsByClassName("signuserName")[0];
var signpassword=document.getElementsByClassName("signpassword");
function Sign(){
    $.ajax({
        type:'post',
        url:"../user/insertUser",
        async:true,
        data:{
            account:signuserName.value,
            password:signpassword[0].value,
            repassword:signpassword[1].value
        },
        success:function(data){
            if(data.msg=="用户名已存在"){
                Tips("用户名已存在");
            }else{
                Tips("注册成功");
                loginBtnContainer.style.left="100%";
                handoverSign.style.right="100%";
                signuserName.value="";
                signpassword[0].value="";
                signpassword[1].value="";
                signTrue.value="";
                setTimeout(function(){
                    handoverLogin.style.left="0";
                    singBtnContainer.style.right="0";
                },300);
            }
        }
    });
}
signpassword[0].onfocus=function(){
    signpassword[0].style.border="";
    signpassword[1].style.border="";
}
signpassword[1].onfocus=function(){
    signpassword[0].style.border="";
    signpassword[1].style.border="";
}
function Tips(i){
    tips.innerHTML=i;
    tips.style.top="56px";
    let timer=setTimeout(function(){
        tips.style.top="-56px";
        clearTimeout(timer);
    },1000);
}
